#pragma once

#include "SignalEvent.h"

#include "Signal.h"

namespace uml {

SignalEvent::SignalEvent(const QString& umlType)
    : MessageEvent(umlType) {}

void SignalEvent::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    MessageEvent::fromJson(json, errorList);
    signal_ = JsonSerializable::create<Signal>(json.value("signal"), errorList);

}

void SignalEvent::toJson(QJsonObject& json) {
    MessageEvent::toJson(json);
    if (signal_) {
        QJsonObject signal_json;
        signal_->toJson(signal_json);
        json.insert("signal", signal_json);
    }
}

/// <summary>
/// signal getter
/// The specific Signal that is associated with this SignalEvent.
/// </summary>
shared_ptr<Signal> SignalEvent::signal() const {
    return signal_;
}

/// <summary>
/// signal setter
/// The specific Signal that is associated with this SignalEvent.
/// </summary>
void SignalEvent::setSignal(shared_ptr<Signal> value) {
    signal_ = value;
}

} // namespace uml
